package com.lfy.auth.listener;

import com.lfy.auth.domain.msg.RemoveFileMsg;
import com.lfy.commons.config.file.MinioConfig;
import com.lfy.commons.utils.MinioUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 文件事件
 *
 * @author <a href="https://www.lvfeiy.top">吕飞扬</a>
 * @date 2023/10/20 15:19
 */
@Component
@Slf4j
public class FileListener {
    @Resource
    private MinioUtil minioUtil;
    @Resource
    private MinioConfig minioConfig;

    @EventListener(classes = RemoveFileMsg.class)
    @Async
    public void removeHeadImg(RemoveFileMsg msg){
        String fileName = msg.getFileName();
        minioUtil.removeObjects(minioConfig.getBucketName(), Arrays.asList(fileName));
    }
}
